#include "StdAfx.h"
#include "AnalogSensorDevice.h"
#include "RobotInstance.h"


namespace RobotPlant { namespace RobotProxy{

	AnalogSensorDevice::AnalogSensorDevice(RobotInstance* pParent,joint::spawn_type e):DeviceBase(pParent,e)
	{
		_deviceType = DeviceTypeEnum::AnalogSensor;
		_deviceIndex = 1;
		chord(GetNormalizedMeasurement, &AnalogSensorDevice::Handler_GetNormalizedMeasurement);
		chord(GetRawMeasurement, &AnalogSensorDevice::Handler_GetRawMeasurement);
		chord(GetRawMeasurementRange, &AnalogSensorDevice::Handler_GetRawMeasurementRange);
		chord(GetLastTimeStamp, &AnalogSensorDevice::Handler_GetLastTimeStamp);
	}

	AnalogSensorDevice::~AnalogSensorDevice()
	{
	}

	double AnalogSensorDevice::Handler_GetNormalizedMeasurement(void_t)
	{
		boost::mutex::scoped_lock lock(this->_pParent->_mutex);

		double value = -1;
		RobDeviceInterface robDeviceInterface;
		string addr = _pParent->_soapServer;
		robDeviceInterface.endpoint = addr.data();
		if (robDeviceInterface.ns1__AnalogSensor_GetNormalizedMeasurement(this->_deviceIndex,&value) != SOAP_OK)
		{
			value = -1;
		}

		return value;
	}

	double AnalogSensorDevice::Handler_GetRawMeasurement(void_t)
	{
		boost::mutex::scoped_lock lock(this->_pParent->_mutex);

		double value = -1;
		RobDeviceInterface robDeviceInterface;
		string addr = _pParent->_soapServer;
		robDeviceInterface.endpoint = addr.data();
		if (robDeviceInterface.ns1__AnalogSensor_GetRawMeasurement(this->_deviceIndex,&value) != SOAP_OK)
		{
			value = -1;
		}

		return value;
	}

	double AnalogSensorDevice::Handler_GetRawMeasurementRange(void_t)
	{
		boost::mutex::scoped_lock lock(this->_pParent->_mutex);

		double value = -1;
		RobDeviceInterface robDeviceInterface;
		string addr = _pParent->_soapServer;
		robDeviceInterface.endpoint = addr.data();
		if (robDeviceInterface.ns1__AnalogSensor_GetRawMeasurementRange(this->_deviceIndex,&value) != SOAP_OK)
		{
			value = -1;
		}

		return value;
	}

	time_t AnalogSensorDevice::Handler_GetLastTimeStamp(void_t)
	{
		boost::mutex::scoped_lock lock(this->_pParent->_mutex);

		time_t value = -1;
		RobDeviceInterface robDeviceInterface;
		string addr = _pParent->_soapServer;
		robDeviceInterface.endpoint = addr.data();
		if (robDeviceInterface.ns1__AnalogSensor_GetLastTimeStamp(this->_deviceIndex,&value) != SOAP_OK)
		{
			value = -1;
		}

		return value;
	}
}}